<?php
	/*
	  include once file DBConfig.php
	 */
	include('DbConfig.php');
	
	class baseDAO{
		protected $connection;
		
		public function __construct(){			
		}
		
		protected function init(){
			global $dbConfig_hostName;
			global $dbConfig_databaseName;
			global $dbConfig_userName;
			global $dbConfig_password; 
		
			try{	
				// $this->connection = new PDO('mysql:host=' . $dbConfig_hostName . ';dbname='. $dbConfig_databaseName.'', $dbConfig_userName, $dbConfig_password);
				
                                //$this->connection = new PDO('mysql:host=localhost;dbname=cenvue_formula', 'cenvue_phongvan', '8752786');
                                $this->connection = new PDO('mysql:host=localhost;dbname=formula', 'root', '');
				//$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			}catch (PDOException $e){
				print $e->getMessage();
			}
		}
		
		protected function query($sql){
			try{
				$this->init();
				$stmt = $this->connection->query($sql);
				$this->connection = null;				
				return $stmt;
			}catch(PDOException $e){
				print $e->getMessage();
			}
		}
		
		protected function firstRow($sql){
			$rs = $this->query($sql);
			return $rs;
		}
		
		protected function execute($sql){
			try{
				$this->init();
				$this->connection->exec($sql);
				$this->connection = null;
			}catch(PDOException $e){
				print $e->getMessage();
			}
		}
		
		public function getId($sql){
			$objID = "";
			try{
				$rs = $this->query($sql);
				while($row = $rs->fetch(PDO::FETCH_OBJ))
				{
					$objID = $objID.$row->ma_hang."---".$row->ten_hang;
				}
				return $objID;
			}catch(PDOException $e){
				print $e->getMessage();
			}
		}
}
?>